#include "buf.h"

#include "printf.h"
#include "defs.h"

void buf_init(struct buf * b, struct buf * prev, struct buf * next){
  b->valid = 0;
  b->disk = 0;
  b->blockno = 0;
  b->dev = 0;
  initsleeplock(&b->lock, "buffer");
  b->refcnt = 0;
  b->prev = prev;
  b->next = next;
}


void buf_init_zero_data(struct  buf * b, uint blockno){
  buf_init(b, 0, 0);
  memset(b->data, 0, BSIZE);
  b->blockno = blockno;
}
void buf_set_char(struct buf * b, uchar c){
  memset(b->data, c, BSIZE);
}

void buf_print(struct buf * p){
  printf("cur:%p, prev:%p next:%p blockno:%d, refcnt:[%u], dev:%u, disk:%d, valid:%d \n", p, p->prev, p->next, p->blockno, p->refcnt, p->dev, p->disk, p->valid);
}
